#include "pgp.h"
#include "system.h"
#include "signal.h"
#include "language.h"
#include "exitpgp.h"

#ifdef	M_XENIX
char *strstr();
long time();
#endif

#ifdef SIGINT

/* This function is called if a BREAK signal is sent to the program.  In this
   case we zap the temporary files.
 */
void breakHandler(int sig)
{
#ifdef UNIX
	if (sig == SIGPIPE) {
		signal(SIGPIPE, SIG_IGN);
		exitPGP(INTERRUPT);
	}
	if (sig != SIGINT)
		sprintf(sErrorText, "\nreceived signal %d\n", sig);
	else
#endif
		sprintf(sErrorText, LANG("\nStopped at user request\n"));
	exitPGP(INTERRUPT);
}
#endif

void initsigs()
{
#ifdef PGPCATCHSIGNALS

#ifdef MSDOS
#ifndef OS2
#ifdef __TURBOC__
	harderr(dostrap);
#else							/* MSC */
#ifndef __GNUC__				/* DJGPP's not MSC */
	_harderr(dostrap);
#endif
#endif
#endif
#endif							/* MSDOS */
#ifdef SIGINT
	if (signal(SIGINT, SIG_IGN) != SIG_IGN)
		signal(SIGINT, breakHandler);
#if defined(UNIX) || defined(VMS) || defined(ATARI)
#ifndef __PUREC__ /* PureC doesn't recognise all signals */
	if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
		signal(SIGHUP, breakHandler);
	if (signal(SIGQUIT, SIG_IGN) != SIG_IGN)
		signal(SIGQUIT, breakHandler);
#endif
#ifdef UNIX
	signal(SIGPIPE, breakHandler);
#endif
	signal(SIGTERM, breakHandler);
#ifdef MACTC5
		signal(SIGABRT,breakHandler);
		signal(SIGTERM,breakHandler);
#ifndef DEBUG
	signal(SIGTRAP, breakHandler);
	signal(SIGSEGV, breakHandler);
	signal(SIGILL, breakHandler);
#ifdef SIGBUS
	signal(SIGBUS, breakHandler);
#endif
#endif							/* DEBUG */
#endif							/* MACTC5 */
#endif							/* UNIX */
#endif							/* SIGINT */
#endif 							/* PGPCATCHSIGNALS */
}								/* initsigs */
